import time

import pytest
from selenium import webdriver

from .date_picker import DatePicker
from Lib.zcm.common.ui.Selector import Selector


def test_setValue_antd4x():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://ant.design/components/date-picker-cn/")
    test_dataes = [
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[1]',
         'date': '2020-09-20'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[2]',
         'date': '2020-40周'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[3]',
         'date': '2020-04'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[4]',
         'date': '2020-Q2'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[5]',
         'date': '2023'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//div[@class="ant-picker-input"])[5]',
         'date': '2023'},
        {'selector': '(//*[@id="components-date-picker-demo-range-picker"]//div[@class="ant-space-item"])[1]',
         'date': '2020-09-20,2020-10-11'},
    ]
    try:
        for test_data in test_dataes:
            picker = DatePicker(browser, test_data['selector'], Selector.XPATH)
            date = test_data['date']
            picker.setValue(date)
        time.sleep(10)
    finally:
        browser.close()


def test_setValue_antd3x():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://3x.ant.design/components/date-picker-cn/")

    test_dataes = [
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//span[@class="ant-calendar-picker"])[1]',
         'date': '2020-09-20'},
        {'selector': '(//*[@id="components-date-picker-demo-basic"]//span[@class="ant-calendar-picker"])[3]',
         'date': '2020-05-20,2020-09-20'},
        {'selector': '(//*[@id="components-date-picker-demo-format"]//span[@class="ant-calendar-picker"])[1]',
         'date': '2020/01/20'},
        {'selector': '(//*[@id="components-date-picker-demo-format"]//span[@class="ant-calendar-picker"])[2]',
         'date': '20/03/2020'},
        {'selector': '(//*[@id="components-date-picker-demo-format"]//span[@class="ant-calendar-picker"])[4]',
         'date': '2020/01/20,2020/10/01'},
    ]
    try:
        for test_data in test_dataes:
            picker = DatePicker(browser, test_data['selector'], Selector.XPATH)
            date = test_data['date']
            picker.setValue(date)
        time.sleep(10)
    finally:
        pass
        browser.close()


def test_setValue_fishx():
    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get("https://fish.iwhalecloud.com/fish-desktop-x/components/date-picker")
    time.sleep(10)
    try:
        picker = DatePicker(browser,
                            '(//*[@class="w-code-preview-demo-source"]//span[@class="ant-calendar-picker"])[1]',
                            Selector.XPATH)
        # now_date = '2020-09-20'
        now_date = '2020-09-30'
        picker.setValue(now_date)
        time.sleep(10)
    finally:
        browser.close()


if __name__ == '__main__':
    pytest.main(['-s', 'date_picker_test.py'])
